package com.ljkj.blockpay.ui.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.kongzue.baseokhttp.util.JsonMap;
import com.ljkj.blockpay.R;
import com.ljkj.blockpay.basedata.BaseActivity;
import com.ljkj.blockpay.databinding.ActivityTransferBinding;
import com.ljkj.blockpay.presenter.TransferPresenter;
import com.ljkj.blockpay.presenter.inter.TransferInter;
import com.ljkj.blockpay.util.ToggleToActivity;
import com.ljkj.blockpay.widget.ClickListener;
import com.ljkj.blockpay.widget.CommonDialog;
import com.ljkj.blockpay.widget.VerifyCodeView;
import com.luck.picture.lib.tools.ToastUtils;

/**
 * 转账界面
 */
public class TransferActivity extends BaseActivity<ActivityTransferBinding,TransferPresenter> implements TransferInter.TransferInterView,ClickListener {

    private CommonDialog mTextDialog;
    private String searchUser;
    private String bizToken;
    private String account;
    private String headUrl;
    @Override
    public int initContentView() {
        return R.layout.activity_transfer;
    }

    @Override
    protected TransferPresenter createPresenter() {
        return new TransferPresenter(this,this);
    }

    @Override
    protected void init(Bundle savedInstanceState) {

        binding.setOnClick(this::onClick);
        binding.tvTitle.setTitleContent(R.string.hometransfer);
        binding.tvTitle.setLeftBackFinish(this);

        initlistener();
    }

    private void initlistener() {
        binding.etSearchaccount.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!editable.toString().isEmpty()){
                    binding.btnAgree.setBackground(getResources().getDrawable(R.drawable.btnbg));
                }
            }
        });

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_agree:
                searchUser = binding.etSearchaccount.getText().toString();
                getPresenter().searchUserinfo(searchUser);

                break;
        }
    }


    @Override
    public void SearchInfoSuccess(JsonMap jsonMap) {
        bizToken = jsonMap.getString("bizToken");
        account = jsonMap.getString("account");
        headUrl = jsonMap.getString("headUrl");
        ToggleToActivity.toTransferAccountActivity(this,bizToken,account,headUrl);

    }
}